<template>
  <div>
 <el-dialog
      title="修改目录"
      :visible="dialogVisible"
      width="30%"
      @close="closeDialog"
      @open="openDialog"
    >
      <el-form>
        <el-form-item
        width="200px"
          label="所属学科"
          prop="subject"
          v-model="mlForm.subject"
        >
          <el-select
            v-model="value"
             filterable
            placeholder="请选择"
          >
            <el-option
              v-for="item in subjectlist"
              :key="item.id"
              :label="item.subjectName"
              :value="item.subjectName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="目录名称" prop="mlname" >
              <el-input v-model="mlForm.mlname" width="100px"></el-input>
            </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('closeDialog')">取 消</el-button>
        <el-button type="primary" @click="$emit('closeDialog')"
          >确 定</el-button
        >
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { list as xklist } from '../../api/hmmm/subjects'
import { detail as mldetail } from '../../api/hmmm/directorys'
export default {
  data () {
    return {
      params: {
        page: 1,
        pagesize: 100
      },
      subjectlist: [],
      mlForm: {
        subject: '',
        mlname: ''
      },
      value: ''
    }
  },
  props: {
    dialogVisible: {
      type: Boolean,
      required: true
    },
    mlId: {
      type: Number,
      required: true
    },
    type: {
      type: String,
      required: true
    }
  },
  methods: {
    closeDialog () {
      this.$emit('closeDialog')
      console.log(this.mlId)
      console.log(this.value)
    },
    async  openDialog () {
      if (this.type === 'edit') {
        const res = await xklist(this.params)
        console.log('学科列表：', res)
        this.subjectlist = res.data.items
        // console.log(this.mmlist)

        const res1 = await mldetail({ id: this.mlId })
        console.log('详情得id', res1)
        this.mlForm.mlname = res1.data.directoryName
        console.log(res1.data.subjectID)

        console.log('目录列表', res.data.items)
        const a = res.data.items.filter(item => {
          return item.id === res1.data.subjectID
        })
        console.log(a)

        this.value = a[0].subjectName
      } else {
      }
    }
  }
}
</script>

<style>

</style>
